package com.lwm.base;

import org.junit.Test;

/**
 * @author liweimin
 * @date 2020/9/24 9:38
 * @description
 */
public class ExceptionTest {
    @Test
    public void test01() {
        int a = 0, b = 1;

        try {
            System.out.println(b / a);
        } catch (ArithmeticException e) {
            //catch参数为异常捕捉的类型
            //catch捕捉从小到大否则会报错
            System.out.println(e.toString());
        } finally {
            System.out.println("finally");
        }
    }

    @Test
    public void test02() {
        //在方法中抛出异常
        int a = 0;
        if (a == 0)
            throw new ArithmeticException();
    }
    public void in(int a, int b) throws Exception {
        System.out.println("Throws");
    }
    @Test
    public void test03() throws MyException {
        int a = 19;
        if(a>10)
            throw new MyException(""+a);
    }
}
